﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace employee.Controls
{
    public partial class emEmergency : common.controls.baseUserControl  
    {
        public emEmergency()
        {
            InitializeComponent();
        }

        BindingSource lastDataSrc = null;
        public new void Refresh()
        {
            if (this.lastDataSrc != null) SetDataSource(this.lastDataSrc);
        }
        protected void SetDataSource(BindingSource dataSrc)
        {
            common.BindingLibs.BindObject(contactName1Ed, dataSrc, DataAccess.DataCache.myBaseDS.employee.emerContact1Column.ColumnName);
            common.BindingLibs.BindObject(contactName2Ed, dataSrc, DataAccess.DataCache.myBaseDS.employee.emerContact2Column.ColumnName);

            common.BindingLibs.BindObject(contactPhone1Ed, dataSrc, DataAccess.DataCache.myBaseDS.employee.emerContactPhone1Column.ColumnName);
            common.BindingLibs.BindObject(contactPhone2Ed, dataSrc, DataAccess.DataCache.myBaseDS.employee.emerContactPhone2Column.ColumnName);
            
            common.BindingLibs.BindObject(contactAddr1Ed, dataSrc, DataAccess.DataCache.myBaseDS.employee.emerContactAddr1Column.ColumnName);
            common.BindingLibs.BindObject(contactAddr2Ed, dataSrc, DataAccess.DataCache.myBaseDS.employee.emerContactAddr2Column.ColumnName);

            common.BindingLibs.BindObject(noteEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.emerNotesColumn.ColumnName);

            contactName1Ed.MaxLength = DataAccess.DataCache.myBaseDS.employee.emerContact1Column.MaxLength;
            contactAddr1Ed.MaxLength = DataAccess.DataCache.myBaseDS.employee.emerContactAddr1Column.MaxLength;
            contactPhone1Ed.MaxLength = DataAccess.DataCache.myBaseDS.employee.emerContactPhone1Column.MaxLength;

            contactName2Ed.MaxLength = DataAccess.DataCache.myBaseDS.employee.emerContact2Column.MaxLength;
            contactAddr2Ed.MaxLength = DataAccess.DataCache.myBaseDS.employee.emerContactAddr2Column.MaxLength;
            contactPhone2Ed.MaxLength = DataAccess.DataCache.myBaseDS.employee.emerContactPhone2Column.MaxLength;

            noteEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.emerNotesColumn.MaxLength;
        }

        public virtual void Init(BindingSource dataSrc)
        {
            SetDataSource(dataSrc);
            this.lastDataSrc = dataSrc;
        }
        public virtual bool CheckData()
        {
            bool retVal = true;
            ClearNotifyError();
            if (contactName1Ed.Text.Trim() != "" && contactPhone1Ed.Text.Trim()=="")
            {
                //NotifyError(contactPhone1Lbl);
                //retVal = false;
            }
            
            if (contactName2Ed.Text.Trim() != "" && contactPhone2Ed.Text.Trim() == "")
            {
                //NotifyError(contactPhone2Lbl);
                //retVal = false;
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            state = !state;
            contactName1Ed.Enabled = state;
            contactAddr1Ed.Enabled = state;
            contactPhone1Ed.Enabled = state;

            contactName2Ed.Enabled = state;
            contactAddr2Ed.Enabled = state;
            contactPhone2Ed.Enabled = state;

            noteEd.Enabled = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            contactName1Ed.Focus();
        }
    }
}
